<template>
  <el-container class="app">
    <el-aside width="auto">
      <router-link to="/app" class="logo"></router-link>
      <!-- <h2 class="logo">vivo商城管理</h2> -->
      <el-menu class="mymenu"
        :collapse="$store.state.collapse"
        :default-active="defaultActive"
        unique-opened
        router>
        <el-submenu index="1">
          <template slot="title">
            <i class="el-icon-s-tools"></i><span>控制面板</span>
          </template>
          <el-menu-item index="/app/dashboard">仪表盘</el-menu-item>
          <el-menu-item index="1-2">选项2</el-menu-item>
          <el-menu-item index="1-3">选项3</el-menu-item>
          <el-submenu index="1-4">
            <template slot="title">选项4</template>
            <el-menu-item index="1-4-1">选项1</el-menu-item>
          </el-submenu>
        </el-submenu>
        <el-submenu index="2">
          <template slot="title">
            <i class="el-icon-s-custom"></i><span slot="title">用戶管理</span>
          </template>
          <el-menu-item index="/app/admin">用户列表</el-menu-item>
          <el-menu-item index="2-2">选项2</el-menu-item>
        </el-submenu>
        <el-submenu index="3">
          <template slot="title">
            <i class="el-icon-magic-stick"></i><span slot="title">角色管理</span>
          </template>
          <el-menu-item index="/app/role">角色列表</el-menu-item>
        </el-submenu>
        <el-submenu index="4">
          <template slot="title">
            <i class="el-icon-s-goods"></i><span slot="title">产品管理</span>
          </template>
          <el-menu-item index="/app/productcate">分类列表</el-menu-item>
          <el-menu-item index="/app/product">产品列表</el-menu-item>
        </el-submenu>
        <el-submenu index="5">
          <template slot="title">
            <i class="el-icon-picture"></i><span slot="title">轮播管理</span>
          </template>
          <el-menu-item index="/app/carousel">轮播列表</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <div>
          <el-button plain :icon="iconMenu" size="small" class="menubtn" @click="$store.commit('toggleMenu')"></el-button>
        </div>
        <div class="nav">
          <router-link to="" class="home"><i class="el-icon-house"></i></router-link>
          <el-badge :value="12" class="notice">
            <i class="el-icon-bell"></i>
          </el-badge>
           <el-dropdown trigger="click" @command="handleCommand">
            <span class="myacater">
              <el-avatar :size="32" :src="userInfo.avatar || require('@/assets/img/nophoto.png')" class="el-avater"></el-avatar>
              {{userInfo.nickName || userInfo.userName}}
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-setting">个人设置</el-dropdown-item>
              <el-dropdown-item icon="el-icon-lock" command="uppassword">修改密码</el-dropdown-item>
              <el-dropdown-item icon="el-icon-refresh">在线升级</el-dropdown-item>
              <el-dropdown-item icon="el-icon-switch-button" divided command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>

  </el-container>
</template>

<script>
export default {
  data () {
    return {
      defaultActive: location.hash.slice(1)
    }
  },
  created () {
    this.$store.dispatch('admin/getInfo')
  },
  computed: {
    userInfo () {
      return this.$store.state.admin.info
    },
    iconMenu () {
      return 'el-icon-s-' + (this.$store.state.collapse ? 'un' : '') + 'fold'
    }
  },
  watch: {
    $route (to) {
      this.defaultActive = location.hash.slice(1)
    }
  },
  methods: {
    handleCommand (command) {
      if (command === 'logout') {
        this.$confirm('你确定要退出系统吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          localStorage.removeItem('ZY-Token')
          // this.$router.replace('/login')
          location.reload()
          this.$message({
            type: 'success',
            message: '注销成功!',
            duration: 2000
          })
        }).catch(() => {})
      }
    }
  }
}
</script>
<style lang="less">
  .mymenu {
    background-color:#44C087;
    border-right: none;
    &:not(.el-menu--collapse) {
      width: 200px;
    }
    .el-menu {
      background-color: transparent;
    }
    .el-submenu__title,
    .el-menu-item {
      font-size: 15px;
      color: #fff;
      i {
        color: #c4e9b5;
      }
      &:hover {
        background-color: rgba(0, 0, 0, .1);
        color: #000;
      }
    }
    .el-menu-item {
      background-color: transparent;
      &.is-active {
        background-color: rgba(4, 87, 48, 0.45);
        color: #4af317;
      }
    }
  }
</style>
<style lang="less" scoped>
  .app {
    height: 100vh;

    .el-aside {
      background-color: #44C087;
      color: #333;
      box-shadow: 3px 0 5px rgba(0, 0, 0, .15);
      z-index: 10;
      .logo{
        display: block;
        height: 60px;
        background: url(../assets/img/logo.png) no-repeat 14px 50%;
      }
    }
    .el-header{
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: rgba(255, 255, 255, 0.7);
      color: #333;
      box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
      z-index: 5;
    }
    .el-button--small {
      padding: 6.5px 12px;
      font-size: 16px;
    }
    .nav {
      display: flex;
      align-items: center;
      .home {
        margin-right: 20px;
      }
      .notice {
        margin-right: 30px;
      }
      .myacater {
        display: flex;
        align-items: center;
        cursor: pointer;
        .el-avater {
          margin-right: 10px;
        }
      }
      [class*="el-icon-"] {
        font-size: 18px;
      }
    }
    .el-main {
      background-color: #E9EEF3;
    }
  }

</style>
